package org.jivesoftware.smackx.workgroup.agent;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.AndFilter;
import org.jivesoftware.smack.filter.FromContainsFilter;
import org.jivesoftware.smack.filter.OrFilter;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.DefaultPacketExtension;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.IQ.Type;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Presence.Mode;
import org.jivesoftware.smack.packet.Presence.Type;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.Form;
import org.jivesoftware.smackx.ReportedData;
import org.jivesoftware.smackx.packet.MUCUser;
import org.jivesoftware.smackx.packet.MUCUser.Invite;
import org.jivesoftware.smackx.workgroup.MetaData;
import org.jivesoftware.smackx.workgroup.WorkgroupInvitationListener;
import org.jivesoftware.smackx.workgroup.ext.history.AgentChatHistory;
import org.jivesoftware.smackx.workgroup.ext.history.ChatMetadata;
import org.jivesoftware.smackx.workgroup.ext.macros.MacroGroup;
import org.jivesoftware.smackx.workgroup.ext.macros.Macros;
import org.jivesoftware.smackx.workgroup.ext.notes.ChatNotes;
import org.jivesoftware.smackx.workgroup.packet.DepartQueuePacket;
import org.jivesoftware.smackx.workgroup.packet.MonitorPacket;
import org.jivesoftware.smackx.workgroup.packet.OccupantsInfo;
import org.jivesoftware.smackx.workgroup.packet.OfferRequestProvider.OfferRequestPacket;
import org.jivesoftware.smackx.workgroup.packet.OfferRevokeProvider.OfferRevokePacket;
import org.jivesoftware.smackx.workgroup.packet.QueueDetails;
import org.jivesoftware.smackx.workgroup.packet.QueueOverview;
import org.jivesoftware.smackx.workgroup.packet.RoomInvitation;
import org.jivesoftware.smackx.workgroup.packet.RoomInvitation.Type;
import org.jivesoftware.smackx.workgroup.packet.RoomTransfer;
import org.jivesoftware.smackx.workgroup.packet.RoomTransfer.Type;
import org.jivesoftware.smackx.workgroup.packet.SessionID;
import org.jivesoftware.smackx.workgroup.packet.Transcript;
import org.jivesoftware.smackx.workgroup.packet.Transcripts;
import org.jivesoftware.smackx.workgroup.settings.GenericSettings;
import org.jivesoftware.smackx.workgroup.settings.SearchSettings;

public class AgentSession
{
  private Agent agent;
  private AgentRoster agentRoster;
  private Connection connection;
  private final List<WorkgroupInvitationListener> invitationListeners;
  private int maxChats;
  private final Map<String, String> metaData;
  private final List<OfferListener> offerListeners;
  private boolean online = false;
  private PacketListener packetListener;
  private Presence.Mode presenceMode;
  private final List<QueueUsersListener> queueUsersListeners;
  private Map<String, WorkgroupQueue> queues;
  private TranscriptManager transcriptManager;
  private TranscriptSearchManager transcriptSearchManager;
  private String workgroupJID;

  public AgentSession(String paramString, Connection paramConnection)
  {
    this.agentRoster = null;
    if (!(paramConnection.isAuthenticated()))
      throw new IllegalStateException("Must login to server before creating workgroup.");
    this.workgroupJID = paramString;
    this.connection = paramConnection;
    this.transcriptManager = new TranscriptManager(paramConnection);
    this.transcriptSearchManager = new TranscriptSearchManager(paramConnection);
    this.maxChats = -1;
    this.metaData = new HashMap();
    this.queues = new HashMap();
    this.offerListeners = new ArrayList();
    this.invitationListeners = new ArrayList();
    this.queueUsersListeners = new ArrayList();
    OrFilter localOrFilter = new OrFilter();
    localOrFilter.addFilter(new PacketTypeFilter(OfferRequestProvider.OfferRequestPacket.class));
    localOrFilter.addFilter(new PacketTypeFilter(OfferRevokeProvider.OfferRevokePacket.class));
    localOrFilter.addFilter(new PacketTypeFilter(Presence.class));
    localOrFilter.addFilter(new PacketTypeFilter(Message.class));
    this.packetListener = new PacketListener(this)
    {
      public void processPacket()
      {
        try
        {
          AgentSession.access$0(this.this$0, paramPacket);
          return;
        }
        catch (Exception localException)
        {
          localException.printStackTrace();
        }
      }
    };
    paramConnection.addPacketListener(this.packetListener, localOrFilter);
    this.agent = new Agent(paramConnection, paramString);
  }

  // ERROR //
  private void fireInvitationEvent(String paramString1, String paramString2, String paramString3, String paramString4, Map paramMap)
  {
    // Byte code:
    //   0: new 148	org/jivesoftware/smackx/workgroup/WorkgroupInvitation
    //   3: dup
    //   4: aload_0
    //   5: getfield 72	org/jivesoftware/smackx/workgroup/agent/AgentSession:connection	Lorg/jivesoftware/smack/Connection;
    //   8: invokevirtual 152	org/jivesoftware/smack/Connection:getUser	()Ljava/lang/String;
    //   11: aload_1
    //   12: aload_0
    //   13: getfield 70	org/jivesoftware/smackx/workgroup/agent/AgentSession:workgroupJID	Ljava/lang/String;
    //   16: aload_2
    //   17: aload_3
    //   18: aload 4
    //   20: aload 5
    //   22: invokespecial 155	org/jivesoftware/smackx/workgroup/WorkgroupInvitation:<init>	(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;)V
    //   25: astore 6
    //   27: aload_0
    //   28: getfield 100	org/jivesoftware/smackx/workgroup/agent/AgentSession:invitationListeners	Ljava/util/List;
    //   31: astore 7
    //   33: aload 7
    //   35: monitorenter
    //   36: aload_0
    //   37: getfield 100	org/jivesoftware/smackx/workgroup/agent/AgentSession:invitationListeners	Ljava/util/List;
    //   40: invokeinterface 161 1 0
    //   45: astore 9
    //   47: aload 9
    //   49: invokeinterface 166 1 0
    //   54: ifne +7 -> 61
    //   57: aload 7
    //   59: monitorexit
    //   60: return
    //   61: aload 9
    //   63: invokeinterface 170 1 0
    //   68: checkcast 172	org/jivesoftware/smackx/workgroup/WorkgroupInvitationListener
    //   71: aload 6
    //   73: invokeinterface 176 2 0
    //   78: goto -31 -> 47
    //   81: astore 8
    //   83: aload 7
    //   85: monitorexit
    //   86: aload 8
    //   88: athrow
    //
    // Exception table:
    //   from	to	target	type
    //   36	86	81	finally
  }

  // ERROR //
  private void fireOfferRequestEvent(OfferRequestProvider.OfferRequestPacket paramOfferRequestPacket)
  {
    // Byte code:
    //   0: new 180	org/jivesoftware/smackx/workgroup/agent/Offer
    //   3: dup
    //   4: aload_0
    //   5: getfield 72	org/jivesoftware/smackx/workgroup/agent/AgentSession:connection	Lorg/jivesoftware/smack/Connection;
    //   8: aload_0
    //   9: aload_1
    //   10: invokevirtual 183	org/jivesoftware/smackx/workgroup/packet/OfferRequestProvider$OfferRequestPacket:getUserID	()Ljava/lang/String;
    //   13: aload_1
    //   14: invokevirtual 186	org/jivesoftware/smackx/workgroup/packet/OfferRequestProvider$OfferRequestPacket:getUserJID	()Ljava/lang/String;
    //   17: aload_0
    //   18: invokevirtual 189	org/jivesoftware/smackx/workgroup/agent/AgentSession:getWorkgroupJID	()Ljava/lang/String;
    //   21: new 191	java/util/Date
    //   24: dup
    //   25: new 191	java/util/Date
    //   28: dup
    //   29: invokespecial 192	java/util/Date:<init>	()V
    //   32: invokevirtual 196	java/util/Date:getTime	()J
    //   35: sipush 1000
    //   38: aload_1
    //   39: invokevirtual 200	org/jivesoftware/smackx/workgroup/packet/OfferRequestProvider$OfferRequestPacket:getTimeout	()I
    //   42: imul
    //   43: i2l
    //   44: ladd
    //   45: invokespecial 203	java/util/Date:<init>	(J)V
    //   48: aload_1
    //   49: invokevirtual 206	org/jivesoftware/smackx/workgroup/packet/OfferRequestProvider$OfferRequestPacket:getSessionID	()Ljava/lang/String;
    //   52: aload_1
    //   53: invokevirtual 210	org/jivesoftware/smackx/workgroup/packet/OfferRequestProvider$OfferRequestPacket:getMetaData	()Ljava/util/Map;
    //   56: aload_1
    //   57: invokevirtual 214	org/jivesoftware/smackx/workgroup/packet/OfferRequestProvider$OfferRequestPacket:getContent	()Lorg/jivesoftware/smackx/workgroup/agent/OfferContent;
    //   60: invokespecial 217	org/jivesoftware/smackx/workgroup/agent/Offer:<init>	(Lorg/jivesoftware/smack/Connection;Lorg/jivesoftware/smackx/workgroup/agent/AgentSession;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Date;Ljava/lang/String;Ljava/util/Map;Lorg/jivesoftware/smackx/workgroup/agent/OfferContent;)V
    //   63: astore_2
    //   64: aload_0
    //   65: getfield 98	org/jivesoftware/smackx/workgroup/agent/AgentSession:offerListeners	Ljava/util/List;
    //   68: astore_3
    //   69: aload_3
    //   70: monitorenter
    //   71: aload_0
    //   72: getfield 98	org/jivesoftware/smackx/workgroup/agent/AgentSession:offerListeners	Ljava/util/List;
    //   75: invokeinterface 161 1 0
    //   80: astore 5
    //   82: aload 5
    //   84: invokeinterface 166 1 0
    //   89: ifne +6 -> 95
    //   92: aload_3
    //   93: monitorexit
    //   94: return
    //   95: aload 5
    //   97: invokeinterface 170 1 0
    //   102: checkcast 219	org/jivesoftware/smackx/workgroup/agent/OfferListener
    //   105: aload_2
    //   106: invokeinterface 223 2 0
    //   111: goto -29 -> 82
    //   114: astore 4
    //   116: aload_3
    //   117: monitorexit
    //   118: aload 4
    //   120: athrow
    //
    // Exception table:
    //   from	to	target	type
    //   71	118	114	finally
  }

  // ERROR //
  private void fireOfferRevokeEvent(OfferRevokeProvider.OfferRevokePacket paramOfferRevokePacket)
  {
    // Byte code:
    //   0: new 227	org/jivesoftware/smackx/workgroup/agent/RevokedOffer
    //   3: dup
    //   4: aload_1
    //   5: invokevirtual 228	org/jivesoftware/smackx/workgroup/packet/OfferRevokeProvider$OfferRevokePacket:getUserJID	()Ljava/lang/String;
    //   8: aload_1
    //   9: invokevirtual 229	org/jivesoftware/smackx/workgroup/packet/OfferRevokeProvider$OfferRevokePacket:getUserID	()Ljava/lang/String;
    //   12: aload_0
    //   13: invokevirtual 189	org/jivesoftware/smackx/workgroup/agent/AgentSession:getWorkgroupJID	()Ljava/lang/String;
    //   16: aload_1
    //   17: invokevirtual 230	org/jivesoftware/smackx/workgroup/packet/OfferRevokeProvider$OfferRevokePacket:getSessionID	()Ljava/lang/String;
    //   20: aload_1
    //   21: invokevirtual 233	org/jivesoftware/smackx/workgroup/packet/OfferRevokeProvider$OfferRevokePacket:getReason	()Ljava/lang/String;
    //   24: new 191	java/util/Date
    //   27: dup
    //   28: invokespecial 192	java/util/Date:<init>	()V
    //   31: invokespecial 236	org/jivesoftware/smackx/workgroup/agent/RevokedOffer:<init>	(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Date;)V
    //   34: astore_2
    //   35: aload_0
    //   36: getfield 98	org/jivesoftware/smackx/workgroup/agent/AgentSession:offerListeners	Ljava/util/List;
    //   39: astore_3
    //   40: aload_3
    //   41: monitorenter
    //   42: aload_0
    //   43: getfield 98	org/jivesoftware/smackx/workgroup/agent/AgentSession:offerListeners	Ljava/util/List;
    //   46: invokeinterface 161 1 0
    //   51: astore 5
    //   53: aload 5
    //   55: invokeinterface 166 1 0
    //   60: ifne +6 -> 66
    //   63: aload_3
    //   64: monitorexit
    //   65: return
    //   66: aload 5
    //   68: invokeinterface 170 1 0
    //   73: checkcast 219	org/jivesoftware/smackx/workgroup/agent/OfferListener
    //   76: aload_2
    //   77: invokeinterface 240 2 0
    //   82: goto -29 -> 53
    //   85: astore 4
    //   87: aload_3
    //   88: monitorexit
    //   89: aload 4
    //   91: athrow
    //
    // Exception table:
    //   from	to	target	type
    //   42	89	85	finally
  }

  // ERROR //
  private void fireQueueUsersEvent(WorkgroupQueue paramWorkgroupQueue, WorkgroupQueue.Status paramStatus, int paramInt, Date paramDate, java.util.Set paramSet)
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 102	org/jivesoftware/smackx/workgroup/agent/AgentSession:queueUsersListeners	Ljava/util/List;
    //   4: astore 6
    //   6: aload 6
    //   8: monitorenter
    //   9: aload_0
    //   10: getfield 102	org/jivesoftware/smackx/workgroup/agent/AgentSession:queueUsersListeners	Ljava/util/List;
    //   13: invokeinterface 161 1 0
    //   18: astore 8
    //   20: aload 8
    //   22: invokeinterface 166 1 0
    //   27: ifne +7 -> 34
    //   30: aload 6
    //   32: monitorexit
    //   33: return
    //   34: aload 8
    //   36: invokeinterface 170 1 0
    //   41: checkcast 244	org/jivesoftware/smackx/workgroup/agent/QueueUsersListener
    //   44: astore 9
    //   46: aload_2
    //   47: ifnull +12 -> 59
    //   50: aload 9
    //   52: aload_1
    //   53: aload_2
    //   54: invokeinterface 248 3 0
    //   59: iload_3
    //   60: bipush 255
    //   62: if_icmpeq +12 -> 74
    //   65: aload 9
    //   67: aload_1
    //   68: iload_3
    //   69: invokeinterface 252 3 0
    //   74: aload 4
    //   76: ifnull +13 -> 89
    //   79: aload 9
    //   81: aload_1
    //   82: aload 4
    //   84: invokeinterface 256 3 0
    //   89: aload 5
    //   91: ifnull -71 -> 20
    //   94: aload 9
    //   96: aload_1
    //   97: aload 5
    //   99: invokeinterface 260 3 0
    //   104: goto -84 -> 20
    //   107: astore 7
    //   109: aload 6
    //   111: monitorexit
    //   112: aload 7
    //   114: athrow
    //
    // Exception table:
    //   from	to	target	type
    //   9	112	107	finally
  }

  private void handlePacket(Packet paramPacket)
  {
    if (paramPacket instanceof OfferRequestProvider.OfferRequestPacket)
    {
      2 local2 = new IQ(this)
      {
        public String getChildElementXML()
        {
          return null;
        }
      };
      local2.setPacketID(paramPacket.getPacketID());
      local2.setTo(paramPacket.getFrom());
      local2.setType(IQ.Type.RESULT);
      this.connection.sendPacket(local2);
      fireOfferRequestEvent((OfferRequestProvider.OfferRequestPacket)paramPacket);
    }
    while (true)
    {
      do
      {
        while (true)
        {
          WorkgroupQueue localWorkgroupQueue;
          DefaultPacketExtension localDefaultPacketExtension;
          do
          {
            Presence localPresence;
            while (true)
            {
              return;
              if (!(paramPacket instanceof Presence))
                break label332;
              localPresence = (Presence)paramPacket;
              String str2 = StringUtils.parseResource(localPresence.getFrom());
              localWorkgroupQueue = (WorkgroupQueue)this.queues.get(str2);
              if (localWorkgroupQueue == null)
              {
                localWorkgroupQueue = new WorkgroupQueue(str2);
                this.queues.put(str2, localWorkgroupQueue);
              }
              QueueOverview localQueueOverview = (QueueOverview)localPresence.getExtension(QueueOverview.ELEMENT_NAME, QueueOverview.NAMESPACE);
              if (localQueueOverview != null)
              {
                if (localQueueOverview.getStatus() == null)
                  localWorkgroupQueue.setStatus(WorkgroupQueue.Status.CLOSED);
                while (true)
                {
                  while (true)
                  {
                    localWorkgroupQueue.setAverageWaitTime(localQueueOverview.getAverageWaitTime());
                    localWorkgroupQueue.setOldestEntry(localQueueOverview.getOldestEntry());
                    fireQueueUsersEvent(localWorkgroupQueue, localQueueOverview.getStatus(), localQueueOverview.getAverageWaitTime(), localQueueOverview.getOldestEntry(), null);
                  }
                  localWorkgroupQueue.setStatus(localQueueOverview.getStatus());
                }
              }
              QueueDetails localQueueDetails = (QueueDetails)paramPacket.getExtension("notify-queue-details", "http://jabber.org/protocol/workgroup");
              if (localQueueDetails == null)
                break;
              localWorkgroupQueue.setUsers(localQueueDetails.getUsers());
              fireQueueUsersEvent(localWorkgroupQueue, null, -1, null, localQueueDetails.getUsers());
            }
            localDefaultPacketExtension = (DefaultPacketExtension)localPresence.getExtension("notify-agents", "http://jabber.org/protocol/workgroup");
          }
          while (localDefaultPacketExtension == null);
          int i = Integer.parseInt(localDefaultPacketExtension.getValue("current-chats"));
          int j = Integer.parseInt(localDefaultPacketExtension.getValue("max-chats"));
          localWorkgroupQueue.setCurrentChats(i);
          localWorkgroupQueue.setMaxChats(j);
        }
        if (paramPacket instanceof Message)
        {
          label332: MUCUser.Invite localInvite;
          Message localMessage = (Message)paramPacket;
          MUCUser localMUCUser = (MUCUser)localMessage.getExtension("x", "http://jabber.org/protocol/muc#user");
          if (localMUCUser != null)
            localInvite = localMUCUser.getInvite();
          while (true)
          {
            while (true)
            {
              if ((localInvite == null) || (!(this.workgroupJID.equals(localInvite.getFrom()))));
              String str1 = null;
              Map localMap = null;
              SessionID localSessionID = (SessionID)localMessage.getExtension("session", "http://jivesoftware.com/protocol/workgroup");
              if (localSessionID != null)
                str1 = localSessionID.getSessionID();
              MetaData localMetaData = (MetaData)localMessage.getExtension("metadata", "http://jivesoftware.com/protocol/workgroup");
              if (localMetaData != null)
                localMap = localMetaData.getMetaData();
              fireInvitationEvent(localMessage.getFrom(), str1, localMessage.getBody(), localMessage.getFrom(), localMap);
            }
            localInvite = null;
          }
        }
      }
      while (!(paramPacket instanceof OfferRevokeProvider.OfferRevokePacket));
      3 local3 = new IQ(this)
      {
        public String getChildElementXML()
        {
          return null;
        }
      };
      local3.setPacketID(paramPacket.getPacketID());
      local3.setType(IQ.Type.RESULT);
      this.connection.sendPacket(local3);
      fireOfferRevokeEvent((OfferRevokeProvider.OfferRevokePacket)paramPacket);
    }
  }

  public void addInvitationListener(WorkgroupInvitationListener paramWorkgroupInvitationListener)
  {
    synchronized (this.invitationListeners)
    {
      if (!(this.invitationListeners.contains(paramWorkgroupInvitationListener)))
        this.invitationListeners.add(paramWorkgroupInvitationListener);
      return;
    }
  }

  public void addOfferListener(OfferListener paramOfferListener)
  {
    synchronized (this.offerListeners)
    {
      if (!(this.offerListeners.contains(paramOfferListener)))
        this.offerListeners.add(paramOfferListener);
      return;
    }
  }

  public void addQueueUsersListener(QueueUsersListener paramQueueUsersListener)
  {
    synchronized (this.queueUsersListeners)
    {
      if (!(this.queueUsersListeners.contains(paramQueueUsersListener)))
        this.queueUsersListeners.add(paramQueueUsersListener);
      return;
    }
  }

  public void close()
  {
    this.connection.removePacketListener(this.packetListener);
  }

  public void dequeueUser(String paramString)
    throws XMPPException
  {
    DepartQueuePacket localDepartQueuePacket = new DepartQueuePacket(this.workgroupJID);
    this.connection.sendPacket(localDepartQueuePacket);
  }

  public Agent getAgent()
  {
    return this.agent;
  }

  public AgentChatHistory getAgentHistory(String paramString, int paramInt, Date paramDate)
    throws XMPPException
  {
    AgentChatHistory localAgentChatHistory1;
    AgentChatHistory localAgentChatHistory2;
    if (paramDate != null)
      localAgentChatHistory1 = new AgentChatHistory(paramString, paramInt, paramDate);
    while (true)
    {
      localAgentChatHistory1.setType(IQ.Type.GET);
      localAgentChatHistory1.setTo(this.workgroupJID);
      PacketCollector localPacketCollector = this.connection.createPacketCollector(new PacketIDFilter(localAgentChatHistory1.getPacketID()));
      this.connection.sendPacket(localAgentChatHistory1);
      localAgentChatHistory2 = (AgentChatHistory)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
      localPacketCollector.cancel();
      if (localAgentChatHistory2 != null)
        break;
      throw new XMPPException("No response from server.");
      localAgentChatHistory1 = new AgentChatHistory(paramString, paramInt);
    }
    if (localAgentChatHistory2.getError() != null)
      throw new XMPPException(localAgentChatHistory2.getError());
    return localAgentChatHistory2;
  }

  public AgentRoster getAgentRoster()
  {
    if (this.agentRoster == null)
      this.agentRoster = new AgentRoster(this.connection, this.workgroupJID);
    int i = 0;
    if ((this.agentRoster.rosterInitialized) || (i > 2000))
      return this.agentRoster;
    try
    {
      Thread.sleep(500L);
      label56: i += 500;
    }
    catch (Exception localException)
    {
      break label56:
    }
  }

  public Map getChatMetadata(String paramString)
    throws XMPPException
  {
    ChatMetadata localChatMetadata1 = new ChatMetadata();
    localChatMetadata1.setType(IQ.Type.GET);
    localChatMetadata1.setTo(this.workgroupJID);
    localChatMetadata1.setSessionID(paramString);
    PacketCollector localPacketCollector = this.connection.createPacketCollector(new PacketIDFilter(localChatMetadata1.getPacketID()));
    this.connection.sendPacket(localChatMetadata1);
    ChatMetadata localChatMetadata2 = (ChatMetadata)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    localPacketCollector.cancel();
    if (localChatMetadata2 == null)
      throw new XMPPException("No response from server.");
    if (localChatMetadata2.getError() != null)
      throw new XMPPException(localChatMetadata2.getError());
    return localChatMetadata2.getMetadata();
  }

  public GenericSettings getGenericSettings(Connection paramConnection, String paramString)
    throws XMPPException
  {
    GenericSettings localGenericSettings1 = new GenericSettings();
    localGenericSettings1.setType(IQ.Type.GET);
    localGenericSettings1.setTo(this.workgroupJID);
    PacketCollector localPacketCollector = this.connection.createPacketCollector(new PacketIDFilter(localGenericSettings1.getPacketID()));
    this.connection.sendPacket(localGenericSettings1);
    GenericSettings localGenericSettings2 = (GenericSettings)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    localPacketCollector.cancel();
    if (localGenericSettings2 == null)
      throw new XMPPException("No response from server on status set.");
    if (localGenericSettings2.getError() != null)
      throw new XMPPException(localGenericSettings2.getError());
    return localGenericSettings2;
  }

  public MacroGroup getMacros(boolean paramBoolean)
    throws XMPPException
  {
    boolean bool;
    Macros localMacros2;
    Macros localMacros1 = new Macros();
    localMacros1.setType(IQ.Type.GET);
    localMacros1.setTo(this.workgroupJID);
    if (paramBoolean)
      bool = false;
    while (true)
    {
      localMacros1.setPersonal(bool);
      PacketCollector localPacketCollector = this.connection.createPacketCollector(new PacketIDFilter(localMacros1.getPacketID()));
      this.connection.sendPacket(localMacros1);
      localMacros2 = (Macros)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
      localPacketCollector.cancel();
      if (localMacros2 != null)
        break;
      throw new XMPPException("No response from server.");
      bool = true;
    }
    if (localMacros2.getError() != null)
      throw new XMPPException(localMacros2.getError());
    return localMacros2.getRootGroup();
  }

  public int getMaxChats()
  {
    return this.maxChats;
  }

  public String getMetaData(String paramString)
  {
    return ((String)this.metaData.get(paramString));
  }

  public ChatNotes getNote(String paramString)
    throws XMPPException
  {
    ChatNotes localChatNotes1 = new ChatNotes();
    localChatNotes1.setType(IQ.Type.GET);
    localChatNotes1.setTo(this.workgroupJID);
    localChatNotes1.setSessionID(paramString);
    PacketCollector localPacketCollector = this.connection.createPacketCollector(new PacketIDFilter(localChatNotes1.getPacketID()));
    this.connection.sendPacket(localChatNotes1);
    ChatNotes localChatNotes2 = (ChatNotes)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    localPacketCollector.cancel();
    if (localChatNotes2 == null)
      throw new XMPPException("No response from server.");
    if (localChatNotes2.getError() != null)
      throw new XMPPException(localChatNotes2.getError());
    return localChatNotes2;
  }

  public OccupantsInfo getOccupantsInfo(String paramString)
    throws XMPPException
  {
    OccupantsInfo localOccupantsInfo1 = new OccupantsInfo(paramString);
    localOccupantsInfo1.setType(IQ.Type.GET);
    localOccupantsInfo1.setTo(this.workgroupJID);
    PacketCollector localPacketCollector = this.connection.createPacketCollector(new PacketIDFilter(localOccupantsInfo1.getPacketID()));
    this.connection.sendPacket(localOccupantsInfo1);
    OccupantsInfo localOccupantsInfo2 = (OccupantsInfo)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    localPacketCollector.cancel();
    if (localOccupantsInfo2 == null)
      throw new XMPPException("No response from server.");
    if (localOccupantsInfo2.getError() != null)
      throw new XMPPException(localOccupantsInfo2.getError());
    return localOccupantsInfo2;
  }

  public Presence.Mode getPresenceMode()
  {
    return this.presenceMode;
  }

  public WorkgroupQueue getQueue(String paramString)
  {
    return ((WorkgroupQueue)this.queues.get(paramString));
  }

  public Iterator<WorkgroupQueue> getQueues()
  {
    return Collections.unmodifiableMap(new HashMap(this.queues)).values().iterator();
  }

  public SearchSettings getSearchSettings()
    throws XMPPException
  {
    SearchSettings localSearchSettings1 = new SearchSettings();
    localSearchSettings1.setType(IQ.Type.GET);
    localSearchSettings1.setTo(this.workgroupJID);
    PacketCollector localPacketCollector = this.connection.createPacketCollector(new PacketIDFilter(localSearchSettings1.getPacketID()));
    this.connection.sendPacket(localSearchSettings1);
    SearchSettings localSearchSettings2 = (SearchSettings)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    localPacketCollector.cancel();
    if (localSearchSettings2 == null)
      throw new XMPPException("No response from server.");
    if (localSearchSettings2.getError() != null)
      throw new XMPPException(localSearchSettings2.getError());
    return localSearchSettings2;
  }

  public Transcript getTranscript(String paramString)
    throws XMPPException
  {
    return this.transcriptManager.getTranscript(this.workgroupJID, paramString);
  }

  public Form getTranscriptSearchForm()
    throws XMPPException
  {
    return this.transcriptSearchManager.getSearchForm(StringUtils.parseServer(this.workgroupJID));
  }

  public Transcripts getTranscripts(String paramString)
    throws XMPPException
  {
    return this.transcriptManager.getTranscripts(this.workgroupJID, paramString);
  }

  public String getWorkgroupJID()
  {
    return this.workgroupJID;
  }

  public boolean hasMonitorPrivileges(Connection paramConnection)
    throws XMPPException
  {
    MonitorPacket localMonitorPacket1 = new MonitorPacket();
    localMonitorPacket1.setType(IQ.Type.GET);
    localMonitorPacket1.setTo(this.workgroupJID);
    PacketCollector localPacketCollector = this.connection.createPacketCollector(new PacketIDFilter(localMonitorPacket1.getPacketID()));
    this.connection.sendPacket(localMonitorPacket1);
    MonitorPacket localMonitorPacket2 = (MonitorPacket)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    localPacketCollector.cancel();
    if (localMonitorPacket2 == null)
      throw new XMPPException("No response from server on status set.");
    if (localMonitorPacket2.getError() != null)
      throw new XMPPException(localMonitorPacket2.getError());
    return localMonitorPacket2.isMonitor();
  }

  public boolean isOnline()
  {
    return this.online;
  }

  public void makeRoomOwner(Connection paramConnection, String paramString)
    throws XMPPException
  {
    MonitorPacket localMonitorPacket = new MonitorPacket();
    localMonitorPacket.setType(IQ.Type.SET);
    localMonitorPacket.setTo(this.workgroupJID);
    localMonitorPacket.setSessionID(paramString);
    PacketCollector localPacketCollector = this.connection.createPacketCollector(new PacketIDFilter(localMonitorPacket.getPacketID()));
    this.connection.sendPacket(localMonitorPacket);
    Packet localPacket = localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    localPacketCollector.cancel();
    if (localPacket == null)
      throw new XMPPException("No response from server on status set.");
    if (localPacket.getError() != null)
      throw new XMPPException(localPacket.getError());
  }

  public void removeInvitationListener(WorkgroupInvitationListener paramWorkgroupInvitationListener)
  {
    synchronized (this.invitationListeners)
    {
      this.invitationListeners.remove(paramWorkgroupInvitationListener);
      return;
    }
  }

  public void removeMetaData(String paramString)
    throws XMPPException
  {
    synchronized (this.metaData)
    {
      if ((String)this.metaData.remove(paramString) != null)
        setStatus(this.presenceMode, this.maxChats);
      return;
    }
  }

  public void removeOfferListener(OfferListener paramOfferListener)
  {
    synchronized (this.offerListeners)
    {
      this.offerListeners.remove(paramOfferListener);
      return;
    }
  }

  public void removeQueueUsersListener(QueueUsersListener paramQueueUsersListener)
  {
    synchronized (this.queueUsersListeners)
    {
      this.queueUsersListeners.remove(paramQueueUsersListener);
      return;
    }
  }

  public void saveMacros(MacroGroup paramMacroGroup)
    throws XMPPException
  {
    Macros localMacros = new Macros();
    localMacros.setType(IQ.Type.SET);
    localMacros.setTo(this.workgroupJID);
    localMacros.setPersonal(true);
    localMacros.setPersonalMacroGroup(paramMacroGroup);
    PacketCollector localPacketCollector = this.connection.createPacketCollector(new PacketIDFilter(localMacros.getPacketID()));
    this.connection.sendPacket(localMacros);
    IQ localIQ = (IQ)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    localPacketCollector.cancel();
    if (localIQ == null)
      throw new XMPPException("No response from server on status set.");
    if (localIQ.getError() != null)
      throw new XMPPException(localIQ.getError());
  }

  public ReportedData searchTranscripts(Form paramForm)
    throws XMPPException
  {
    return this.transcriptSearchManager.submitSearch(StringUtils.parseServer(this.workgroupJID), paramForm);
  }

  public void sendRoomInvitation(RoomInvitation.Type paramType, String paramString1, String paramString2, String paramString3)
    throws XMPPException
  {
    4 local4 = new IQ(this, new RoomInvitation(paramType, paramString1, paramString2, paramString3))
    {
      public String getChildElementXML()
      {
        return this.val$invitation.toXML();
      }
    };
    local4.setType(IQ.Type.SET);
    local4.setTo(this.workgroupJID);
    local4.setFrom(this.connection.getUser());
    PacketCollector localPacketCollector = this.connection.createPacketCollector(new PacketIDFilter(local4.getPacketID()));
    this.connection.sendPacket(local4);
    IQ localIQ = (IQ)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    localPacketCollector.cancel();
    if (localIQ == null)
      throw new XMPPException("No response from server.");
    if (localIQ.getError() != null)
      throw new XMPPException(localIQ.getError());
  }

  public void sendRoomTransfer(RoomTransfer.Type paramType, String paramString1, String paramString2, String paramString3)
    throws XMPPException
  {
    5 local5 = new IQ(this, new RoomTransfer(paramType, paramString1, paramString2, paramString3))
    {
      public String getChildElementXML()
      {
        return this.val$transfer.toXML();
      }
    };
    local5.setType(IQ.Type.SET);
    local5.setTo(this.workgroupJID);
    local5.setFrom(this.connection.getUser());
    PacketCollector localPacketCollector = this.connection.createPacketCollector(new PacketIDFilter(local5.getPacketID()));
    this.connection.sendPacket(local5);
    IQ localIQ = (IQ)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    localPacketCollector.cancel();
    if (localIQ == null)
      throw new XMPPException("No response from server.");
    if (localIQ.getError() != null)
      throw new XMPPException(localIQ.getError());
  }

  public void setMetaData(String paramString1, String paramString2)
    throws XMPPException
  {
    synchronized (this.metaData)
    {
      String str = (String)this.metaData.get(paramString1);
      if ((str == null) || (!(str.equals(paramString2))))
      {
        this.metaData.put(paramString1, paramString2);
        setStatus(this.presenceMode, this.maxChats);
      }
      return;
    }
  }

  public void setNote(String paramString1, String paramString2)
    throws XMPPException
  {
    String str = StringUtils.escapeForXML(ChatNotes.replace(paramString2, "\n", "\\n"));
    ChatNotes localChatNotes = new ChatNotes();
    localChatNotes.setType(IQ.Type.SET);
    localChatNotes.setTo(this.workgroupJID);
    localChatNotes.setSessionID(paramString1);
    localChatNotes.setNotes(str);
    PacketCollector localPacketCollector = this.connection.createPacketCollector(new PacketIDFilter(localChatNotes.getPacketID()));
    this.connection.sendPacket(localChatNotes);
    IQ localIQ = (IQ)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    localPacketCollector.cancel();
    if (localIQ == null)
      throw new XMPPException("No response from server on status set.");
    if (localIQ.getError() != null)
      throw new XMPPException(localIQ.getError());
  }

  public void setOnline(boolean paramBoolean)
    throws XMPPException
  {
    if (this.online == paramBoolean);
    while (true)
    {
      while (true)
      {
        return;
        if (!(paramBoolean))
          break;
        Presence localPresence1 = new Presence(Presence.Type.available);
        localPresence1.setTo(this.workgroupJID);
        localPresence1.addExtension(new DefaultPacketExtension("agent-status", "http://jabber.org/protocol/workgroup"));
        Connection localConnection = this.connection;
        PacketFilter[] arrayOfPacketFilter = new PacketFilter[2];
        arrayOfPacketFilter[0] = new PacketTypeFilter(Presence.class);
        arrayOfPacketFilter[1] = new FromContainsFilter(this.workgroupJID);
        PacketCollector localPacketCollector = localConnection.createPacketCollector(new AndFilter(arrayOfPacketFilter));
        this.connection.sendPacket(localPresence1);
        Presence localPresence2 = (Presence)localPacketCollector.nextResult(5000L);
        localPacketCollector.cancel();
        if (!(localPresence2.isAvailable()))
          throw new XMPPException("No response from server on status set.");
        if (localPresence2.getError() != null)
          throw new XMPPException(localPresence2.getError());
        this.online = paramBoolean;
      }
      this.online = paramBoolean;
      Presence localPresence3 = new Presence(Presence.Type.unavailable);
      localPresence3.setTo(this.workgroupJID);
      localPresence3.addExtension(new DefaultPacketExtension("agent-status", "http://jabber.org/protocol/workgroup"));
      this.connection.sendPacket(localPresence3);
    }
  }

  public void setStatus(Presence.Mode paramMode, int paramInt)
    throws XMPPException
  {
    setStatus(paramMode, paramInt, null);
  }

  public void setStatus(Presence.Mode paramMode, int paramInt, String paramString)
    throws XMPPException
  {
    if (!(this.online))
      throw new IllegalStateException("Cannot set status when the agent is not online.");
    if (paramMode == null)
      paramMode = Presence.Mode.available;
    this.presenceMode = paramMode;
    this.maxChats = paramInt;
    Presence localPresence1 = new Presence(Presence.Type.available);
    localPresence1.setMode(paramMode);
    localPresence1.setTo(getWorkgroupJID());
    if (paramString != null)
      localPresence1.setStatus(paramString);
    DefaultPacketExtension localDefaultPacketExtension = new DefaultPacketExtension("agent-status", "http://jabber.org/protocol/workgroup");
    localDefaultPacketExtension.setValue("max-chats", paramInt);
    localPresence1.addExtension(localDefaultPacketExtension);
    localPresence1.addExtension(new MetaData(this.metaData));
    Connection localConnection = this.connection;
    PacketFilter[] arrayOfPacketFilter = new PacketFilter[2];
    arrayOfPacketFilter[0] = new PacketTypeFilter(Presence.class);
    arrayOfPacketFilter[1] = new FromContainsFilter(this.workgroupJID);
    PacketCollector localPacketCollector = localConnection.createPacketCollector(new AndFilter(arrayOfPacketFilter));
    this.connection.sendPacket(localPresence1);
    Presence localPresence2 = (Presence)localPacketCollector.nextResult(5000L);
    localPacketCollector.cancel();
    if (!(localPresence2.isAvailable()))
      throw new XMPPException("No response from server on status set.");
    if (localPresence2.getError() != null)
      throw new XMPPException(localPresence2.getError());
  }

  public void setStatus(Presence.Mode paramMode, String paramString)
    throws XMPPException
  {
    if (!(this.online))
      throw new IllegalStateException("Cannot set status when the agent is not online.");
    if (paramMode == null)
      paramMode = Presence.Mode.available;
    this.presenceMode = paramMode;
    Presence localPresence1 = new Presence(Presence.Type.available);
    localPresence1.setMode(paramMode);
    localPresence1.setTo(getWorkgroupJID());
    if (paramString != null)
      localPresence1.setStatus(paramString);
    localPresence1.addExtension(new MetaData(this.metaData));
    Connection localConnection = this.connection;
    PacketFilter[] arrayOfPacketFilter = new PacketFilter[2];
    arrayOfPacketFilter[0] = new PacketTypeFilter(Presence.class);
    arrayOfPacketFilter[1] = new FromContainsFilter(this.workgroupJID);
    PacketCollector localPacketCollector = localConnection.createPacketCollector(new AndFilter(arrayOfPacketFilter));
    this.connection.sendPacket(localPresence1);
    Presence localPresence2 = (Presence)localPacketCollector.nextResult(5000L);
    localPacketCollector.cancel();
    if (!(localPresence2.isAvailable()))
      throw new XMPPException("No response from server on status set.");
    if (localPresence2.getError() != null)
      throw new XMPPException(localPresence2.getError());
  }
}